<template>
	<view class="my-userinfo-contailner">
		
		<view class="top-box">
			<button class="btn-avatar" type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseavatar">
				<image :src="userInfo.avatarUrl" class="avatar"></image>
			</button>			
			<view class="nickname">{{userInfo.nickName}}</view>
		</view>
		 
		<view class="panel-list">
			<!-- 面板1 -->
			<view class="panel">
				<view class="panel-body">
					<view class="panel-item">
						<text>5</text>
						<text>收藏的店铺</text>
					</view>
					
					<view class="panel-item">
						<text>11</text>
						<text>收藏的商品</text>
					</view>
					
					<view class="panel-item">
						<text>12</text>
						<text>关注的商品</text>
					</view>
					
					<view class="panel-item">
						<text>85</text>
						<text>足迹</text>
					</view>
				</view>
			</view>
			<!-- 面板2 -->
			<view class="panel">
				<view class="panel-title">我的订单</view>
				<view class="panel-body">
					<view class="panel-item">
						<image src="../../static/history.png" class="icon"></image>
						<text>待付款</text>
					</view>
					
					<view class="panel-item">
						<image src='../../static/daishouhuo.png' class="icon"></image>
						<text>待收货</text>
					</view>
					
					<view class="panel-item">
						<image src="../../static/tuikuan.png" class="icon"></image>
						<text>退款/退货</text>
					</view>
					
					<view class="panel-item">
						<image src="../../static/file.png" class="icon"></image>
						<text>全部订单</text>
					</view>
				</view>
			</view>
			
			<!-- 面板3 -->
			<view class="panel">
				<view class="panel-list-item" @click="choose_address">
					<view>收货地址</view>
					<uni-icons type="arrowright" size="15"></uni-icons>
				</view>
				
				<button  style="background-color:white;color:black;" class="panel-list-item" open-type="contact" type='primary'>
					<view>联系客服</view>
					<uni-icons type="arrowright" size="15"></uni-icons>
				</button>
				
				<view class="panel-list-item" @click="logout">
					<view>退出登录</view>
					<uni-icons type="arrowright" size="15"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	export default {
		name:"my-userInfo",
		data() {
			return {
				
			};
		},
		computed:{
			...mapState('user',['userInfo'])
		},
		methods:{
			...mapMutations('user',['updateAddress','updateUserInfo','updateToken']),
			async logout(){
				 const [err,succ]= await uni.showModal({
					title:'窗口提示',
					content:'确认退出登录吗？'
				}).catch(err=>err)
				
				if(succ && succ.confirm){
					this.updateAddress({})
					this.updateUserInfo({})
					this.updateToken('')
				}
			},
			async choose_address(){
				const [err,succ]=await uni.chooseAddress().catch(err=>err)
				if(err===null && succ.errMsg==='chooseAddress:ok'){
					this.updateAddress(succ)
				}
			},
			...mapMutations('user',['updateAddress'])

		}
	}
</script>

<style lang="scss">
.my-userinfo-contailner{
	height: 100%;
	background-color: #f4f4f4;
	.top-box{
		width: 100%;
		height: 400rpx;
		background-color: #C00000;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		button {
				background: #C00000;
				line-height: 80rpx;
				height: auto;
				width: auto;
				padding: 20rpx 30rpx;
				margin: 0;
				display: flex;
				justify-content: center;
				align-items: center;
				.avatar{
					width: 90px;
					height: 90px;
					border-radius: 45px;
					border: 2px solid #ffffff;
					box-shadow: 0 1px 5px black;
				}
				}
		.btn-avatar::after{
			border: none;
		}			
		
		.nickname{
			font-size: 16px;
			margin-top: 10px;
			color: #fff;
			font-weight: bold;
		}
	}
}
.panel-list{
	margin: 0 10px;
	
	position: relative;
	top: -10px;
	.panel{
		background-color: white;
		border-radius: 3px;
		margin-bottom: 8px;
		.panel-title{
			line-height: 45px;
			padding-left: 10px;
			font-size: 15px;
			border-bottom: 1px solid #f4f4f4;
		}
		.panel-body{
			display: flex;
			justify-content: space-around;
			.panel-item{
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				align-items: center;
				font-size: 13px;
				padding: 10px 0;
				.icon{
					width: 35px;
					height: 35px;
				}
			}
		}
	}
	.panel-list-item{
		display: flex;
		justify-content: space-between;
		font-size: 15px;
		padding: 0 10px;
		line-height: 45px;
		
	}
	.panel-list-item::after{
		border: none;
	}
}
</style>